// 给你两个 非空 的链表，表示两个非负的整数。它们每位数字都是按照 逆序 的方式存储的，并且每个节点只能存储 一位 数字。

// 请你将两个数相加，并以相同形式返回一个表示和的链表。

// 你可以假设除了数字 0 之外，这两个数都不会以 0 开头。

class Solution {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        int on = 0;
        ListNode l3 = new ListNode();
        ListNode head = l3;
        while(l1!=null&&l2!=null)
        {
            int v3 = 0;
            int value = l1.val+l2.val+on;
            on = 0;
            if(value<=9)
                v3 = value;
            else
            {
                v3 = value -10;
                on =1 ;
            }
            ListNode a1 = new ListNode(v3);
            head.next = a1;
            head = head.next;
            l1 =l1.next;
            l2 = l2.next;
        }
        while(l1!=null)
        {
            int v3 = 0;
            int value = l1.val+on;
            on = 0;
            if(value<=9)
                v3 = value;
            else
            {
                v3 = value -10;
                on =1 ;
            }
            ListNode a1 = new ListNode(v3);
            head.next = a1;
            head = head.next;
            l1 =l1.next;
        }
        while(l2!=null)
        {
            int v3 = 0;
            int value = l2.val+on;
            on = 0;
            if(value<=9)
                v3 = value;
            else
            {
                v3 = value -10;
                on =1 ;
            }
            ListNode a1 = new ListNode(v3);
            head.next = a1;
            head = head.next;
            l2 =l2.next;
        }
        if(on ==1)
        {
            ListNode a1 = new ListNode(1);
            head.next = a1;
            head = head.next;
            on = 0;
        }
        return l3.next;
    }
}